package Demo1299.Demo20;

import java.lang.reflect.Method;

public class Demo1 {
    public static void main(String[] args) throws Exception {
        A a = new A();
        Object[] arr = {11,22,33};
        Object run = new Demo1().invokeMethod(a, "run", arr);
        System.out.println(run);
    }
    public Object invokeMethod(Object obj, String methodName, Object[] args)  throws Exception{
        Class<? extends Object> aClass = obj.getClass();
        Method m = aClass.getDeclaredMethod(methodName,int[].class);
        try {
            m.setAccessible(true);
        } catch (SecurityException e) { }
        int[] arr = new int[args.length];
        for (int i = 0; i < arr.length; i++) {
            for (int j = i; j < args.length; j++) {
                arr[i] = (int) args[j];
            }
        }
       return m.invoke(obj,arr);
    }
}
